(setq user-full-name "Guile")
(setq user-mail-address "guilin.sun@gmail.com")

;;; initialization for emacs

(require 'color-theme)
;;(color-theme-oswald)

(global-font-lock-mode t)
(transient-mark-mode t)
(global-hi-lock-mode t)

(menu-bar-mode nil)

(auto-image-file-mode t)
(setq default-fill-column 80)
(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)
(setq-default kill-whole-line t)
(setq show-paren-mode t)
(setq show-paren-style 'parenthesis)
(setq mouse-avoidance-mode 'animate)

(require 'header2)

(require 'psvn)

(add-to-list 'load-path "~/elisp/yasnippet")
(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
;;(set-face-background 'yas/field-highlight-face "red")
(yas/load-directory "~/elisp/yasnippet/snippets")

(require 'session)
(add-hook 'after-init-hook 'session-initialize)

(load "desktop")
(desktop-save-mode)
(setq tab-always-indent t)
(setq indent-tabs-mode nil)


;;;CC-mode  http://cc-mode.sourceforge.net/
(require 'cc-mode)

(defun my-c-mode-common-hook()
  (setq indent-tabs-mode nil)
  (setq c-tab-always-indent t)
  (setq c++-tab-always-indent t)
  (setq c-basic-offset 4);; number of spaces to indent
  (setq c-indent-level 4)
  (setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))
  (setq tab-width 8);; for display tab
  (c-set-offset 'inline-open 0)
  (c-set-offset 'friend '-)
  (c-set-offset 'substatement-open 0)

  ;;hungry-delete and auto-newline
  (c-toggle-auto-hungry-state 1)
  ;;Define Keys
  (define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
  (define-key c-mode-base-map [(return)] 'newline-and-indent)
  (define-key c-mode-base-map [(f7)] 'compile)
  (define-key c-mode-base-map [(meta \`)] 'c-indent-command)
  (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
  (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
  (setq c-macro-shrink-window-flag t)
  (setq c-macro-preprocessor "cpp")
  (setq c-macro-cppflags " ")
  (setq c-macro-prompt-flag t)
  (setq hs-minor-mode t)
  (setq abbrev-mode t)
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(add-hook 'js-mode-hook
	  (lambda ()
	    (setq indent-tabs-mode nil)
	    (setq js-tab-always-indent t)
	    (setq js-indent-level 4)
	    (setq tab-width 8);; for display tab
	    ;;hungry-delete and auto-newline
	    (c-toggle-auto-hungry-state 1)
            ;; Scan the file for nested code blocks
            (imenu-add-menubar-index)
            ;; Activate the folding mode
            (hs-minor-mode t)))

(add-hook 'java-mode-hook
	  (lambda ()
	    (setq indent-tabs-mode nil)
	    (setq java-tab-always-indent t)
	    (setq c-basic-offset 2);; number of spaces to indent
	    (setq tab-width 8);; for display tab
	    (c-toggle-auto-hungry-state 0)
            (hs-minor-mode t)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(display-time)
(column-number-mode t)
(setq-default make-backup-files nil)
(fset 'yes-or-no-p 'y-or-n-p)
(setq show-paren-mode t)
(setq show-paren-style 'parenthesis)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'run-ruby "inf-ruby"
  "Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
  "Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook
          '(lambda ()
             (inf-ruby-keys)
						 ))

(add-hook 'ruby-mode-hook
          (lambda()
            (require 'ruby-electric)
            (ruby-electric-mode t)
            ))

(mapcar
 (lambda (mode)
   (let ((mode-hook (intern (concat (symbol-name mode) "-hook")))
	 (mode-map (intern (concat (symbol-name mode) "-map"))))
     (add-hook mode-hook
	       `(lambda nil 
		  (local-set-key 
		   (kbd "RET")
		   (or (lookup-key ,mode-map "\C-j")
		       (lookup-key global-map "\C-j"))))))) '( ruby-mode))


(add-to-list 'load-path "~/elisp/scala-mode")
(require 'scala-mode-auto)
(add-hook 'scala-mode-hook
          '(lambda ()
             (yas/minor-mode-on)
             ))

(setq load-path (cons "~/elisp/erlang-mode"
		      load-path))
(setq erlang-root-dir "/usr/local/otp")
(setq exec-path (cons "/usr/local/otp/bin" exec-path))
(require 'erlang-start)

(setq auto-mode-alist (cons '("\\.lua$" . lua-mode) auto-mode-alist))
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-hook 'lua-mode-hook 'hs-minor-mode)

(yas/load-directory yas/my-directory)

